class QuestionnaireEventController < ApplicationController
	def create
		@questionnaire_event = QuestionnaireEvent.new(params[:questionnaire_event])
    @questionnaire_event.save
    flash_errors(@questionnaire_event) unless @questionnaire_event.errors.empty?
    redirect_to :back
	end
	
	

	def create_multiple
		if !params[:quest_ids].nil?

			begin
				params[:quest_ids].each do |quest_id|
					newParams = {"questionnaire_id" => quest_id}
					newParams.merge!(params[:questionnaire_event])
					@questionnaire_event = QuestionnaireEvent.new(newParams)					
					@questionnaire_event.save
				end
			rescue ArgumentError => e
				flash[:error] = e.message
			end
		end

		redirect_to :controller => 'data_collection', :action => 'edit', :id => params[:data_collection_id]
	end
	
	
	def delete
		@questionnaire_event = QuestionnaireEvent.find(params[:id])		
		@questionnaire = @questionnaire_event.questionnaire
		@questionnaire_event.destroy		
		redirect_to :controller => 'questionnaire', :action => 'edit', :id => @questionnaire.id 
	end
end
